﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using fideeraSoft.Handlers;
using fideeraSoft.Utils;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Drawing;

namespace fideeraSoft.Paneles
{
    public class ConsultaTrazabilidadPorCodigoEnvasadoPanel:PanelGeneral
    {
        private System.Windows.Forms.DataGridView dgvMostrar;
        private System.Windows.Forms.TableLayoutPanel tlpBuscarEnvCod;
        private System.Windows.Forms.TextBox tbBuscarEnvCod;
        private System.Windows.Forms.TableLayoutPanel tlpBotones;
        private System.Windows.Forms.Button btVolver;
        private System.Windows.Forms.DataGridView dgvMostrar2;
        private System.Windows.Forms.Button btBuscarEnvCod;

        private SqlDataAdapter adapter;

        private DataSet ds;

        private int locationBuscarEnvCod=0;
        
        private Button btExportExcel2;
        private Button btExportExcel;
        private TableLayoutPanel tlpExportExcel2;
        private TableLayoutPanel tlpExportExcel;
        int inPosicionDgvMatPrima = 0;
        int locationTablaExportExcel2 = 0;
        private DataGridView dgvMostrar3;
        private Button btExportExcel3;
        private TableLayoutPanel tlpExportExcel3;
        int locationDataGridView = 0;
        
        private int locationTablaExportExcel3=0;
        private int inPosicionDgv3 = 0;



        public ConsultaTrazabilidadPorCodigoEnvasadoPanel(Handler handler)
        {
            this.formatearPanelGeneral(handler);

            try
            {
                InitializeComponent();
                this.formatearTableTitulo("CONSULTA DE TRAZABILIDAD POR CÓDIGO DE ENVASADO");

                string query = "SELECT pr.ID AS [ID Producción], p.nombre AS [Producto], en.ID AS [ID Envasado], en.codigo AS [Código Envasado], en.fechaFin AS [Fecha Fin de Envasado], pr.cantidadPaquetes AS [Cantidad de Paquetes], pr.observacion AS Observación1, pr.observacionFinal AS Observación2, en.observacion AS Observación3, en.observacionFin AS Observación4  FROM Envasado AS en INNER JOIN Produccion AS pr ON en.produccion=pr.ID INNER JOIN Producto AS p ON pr.producto=p.ID WHERE en.fechaFin IS NOT NULL";  
                adapter = SQLclass.obtenerAdapter(query);
                if (adapter != null)
                {
                    ds = new DataSet();
                    adapter.Fill(ds);

                    if (ds.Tables[0].Rows.Count <= 0)
                    {
                        MessageBox.Show("NO HAY NINGUNA PRODUCCION ENVASADA FINALIZADA CARGADA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }else
                    {
                        dgvMostrar.DataSource = ds.Tables[0];
                        if (dgvMostrar.CurrentCell != null)
                        {
                           
                            dgvMostrar.CurrentCell = dgvMostrar.Rows[0].Cells[0];
                            cargarMatPrimaEnDataGridView(dgvMostrar[0, dgvMostrar.CurrentCell.RowIndex].Value.ToString());
                        }
                        else 
                        {
                            
                        }
                    }

                    formatearTablaExportExcel();

                    formatearDataGrid();

                    formatearTablaBuscarEnvCod();

                    
                    formatearDataGridMatPrima();
                    
                    formatearTablaExportExcel2();

                    formatearDataGrid3();

                    formatearTablaExportExcel3();

                    formatearTablaBotones();

                    this.Controls.Add(tlpExportExcel);
                    this.Controls.Add(dgvMostrar);
                    
                    this.Controls.Add(tlpBuscarEnvCod);
                    
                    this.Controls.Add(dgvMostrar2);
                    
                    this.Controls.Add(tlpExportExcel2);

                    this.Controls.Add(dgvMostrar3);

                    this.Controls.Add(tlpExportExcel3);
                    
                    this.Controls.Add(tlpBotones);

                }

                else
                {

                    MessageBox.Show("NO HAY NINGUNA PRODUCCION ENVASADA FINALIZADA CARGADA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.handler.backToPrincipal();
                }

            }
            catch (MiException ex)
            {

                CLogger.Append("[ConsultaTrazabilidadPorCodigoEnvasadoPanel] Exception: " + ex, CLogger.ERROR);      //DEBUG

            }
        }

        #region FORMATEO

        private void formatearTablaExportExcel()
        {
            tlpExportExcel.Controls.Add(btExportExcel);

            // int wid = MetodosGenerales.calcularCenterWidth(handler.FormFrame.Size.Width, tlpExportExcel.Size.Width);

            tlpExportExcel.Location = new System.Drawing.Point(50, this.InitialRealPointVertical);
        }

        private void formatearDataGrid()
        {
            locationDataGridView = this.InitialRealPointVertical + tlpExportExcel.Size.Height + 10;

            dgvMostrar.AutoGenerateColumns = true;
            dgvMostrar.Size = new Size(this.Size.Width - 100, 150);
            dgvMostrar.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.Fill);
            dgvMostrar.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllHeaders);
            dgvMostrar.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dgvMostrar.BorderStyle = BorderStyle.Fixed3D;

            dgvMostrar.Location = new Point(MetodosGenerales.calcularCenterWidth(this.Size.Width, dgvMostrar.Size.Width), locationDataGridView);
        }

        private void formatearTablaBuscarEnvCod()
        {
            tlpBuscarEnvCod.Controls.Add(btBuscarEnvCod);
            tlpBuscarEnvCod.Controls.Add(tbBuscarEnvCod);

            //tlpBuscarProv.Size = new Size(lbBuscarProvCuil.Size.Width + tbBuscarProvCuil.Size.Width + 10,tbBuscarProvCuil.Size.Height);
            locationBuscarEnvCod = this.locationDataGridView + dgvMostrar.Size.Height + 15;

            int wid = MetodosGenerales.calcularCenterWidth(handler.FormFrame.Size.Width, tlpBuscarEnvCod.Size.Width);

            tlpBuscarEnvCod.Location = new Point(wid, locationBuscarEnvCod);


        }


        private void formatearDataGridMatPrima()
        {
            inPosicionDgvMatPrima = locationBuscarEnvCod + tlpBuscarEnvCod.Size.Height + 15;

            dgvMostrar2.AutoGenerateColumns = true;
            dgvMostrar2.Size = new Size(this.Size.Width - 100, 150);
            dgvMostrar2.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.Fill);
            dgvMostrar2.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllHeaders);
            dgvMostrar2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dgvMostrar2.BorderStyle = BorderStyle.Fixed3D;

            dgvMostrar2.Location = new Point(MetodosGenerales.calcularCenterWidth(this.Size.Width, dgvMostrar2.Size.Width), this.inPosicionDgvMatPrima);
        }

        private void formatearTablaExportExcel2()
        {
            tlpExportExcel2.Controls.Add(btExportExcel2);

            locationTablaExportExcel2 = inPosicionDgvMatPrima + dgvMostrar2.Size.Height + 10;

            //int wid = MetodosGenerales.calcularCenterWidth(handler.FormFrame.Size.Width, tlpExportExcel2.Size.Width);

            tlpExportExcel2.Location = new System.Drawing.Point(50, locationTablaExportExcel2);
        }


        private void formatearDataGrid3()
        {
            inPosicionDgv3 = locationTablaExportExcel2 + tlpExportExcel2.Size.Height + 15;

            dgvMostrar3.AutoGenerateColumns = true;
            dgvMostrar3.Size = new Size(this.Size.Width - 100, 150);
            dgvMostrar3.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.Fill);
            dgvMostrar3.AutoResizeRows(DataGridViewAutoSizeRowsMode.AllHeaders);
            dgvMostrar3.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;

            dgvMostrar3.BorderStyle = BorderStyle.Fixed3D;

            dgvMostrar3.Location = new Point(MetodosGenerales.calcularCenterWidth(this.Size.Width, dgvMostrar3.Size.Width), this.inPosicionDgv3);
        }

        private void formatearTablaExportExcel3()
        {
            tlpExportExcel3.Controls.Add(btExportExcel3);

            locationTablaExportExcel3 = inPosicionDgv3 + dgvMostrar3.Size.Height + 10;

            //int wid = MetodosGenerales.calcularCenterWidth(handler.FormFrame.Size.Width, tlpExportExcel2.Size.Width);

            tlpExportExcel3.Location = new System.Drawing.Point(50, locationTablaExportExcel3);
        }

        private void formatearTablaBotones()
        {
            int locationBtCambios = locationTablaExportExcel3 + tlpExportExcel3.Size.Height + 15;
            tlpBotones.Location = new Point(MetodosGenerales.calcularCenterWidth(this.handler.FormFrame.Size.Width, tlpBotones.Size.Width), locationBtCambios);

            tlpBotones.Controls.Add(btVolver);


        }


        #endregion

        #region INICIALIZAR COMPONETES
        private void InitializeComponent()
        {
            this.dgvMostrar = new System.Windows.Forms.DataGridView();
            this.tlpBuscarEnvCod = new System.Windows.Forms.TableLayoutPanel();
            this.tbBuscarEnvCod = new System.Windows.Forms.TextBox();
            this.tlpBotones = new System.Windows.Forms.TableLayoutPanel();
            this.btVolver = new System.Windows.Forms.Button();
            this.btBuscarEnvCod = new System.Windows.Forms.Button();
            this.dgvMostrar2 = new System.Windows.Forms.DataGridView();
            this.btExportExcel2 = new System.Windows.Forms.Button();
            this.btExportExcel = new System.Windows.Forms.Button();
            this.tlpExportExcel2 = new System.Windows.Forms.TableLayoutPanel();
            this.tlpExportExcel = new System.Windows.Forms.TableLayoutPanel();
            this.dgvMostrar3 = new System.Windows.Forms.DataGridView();
            this.btExportExcel3 = new System.Windows.Forms.Button();
            this.tlpExportExcel3 = new System.Windows.Forms.TableLayoutPanel();
            ((System.ComponentModel.ISupportInitialize)(this.dgvMostrar)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgvMostrar2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgvMostrar3)).BeginInit();
            this.SuspendLayout();
            // 
            // dgvMostrar
            // 
            this.dgvMostrar.AllowUserToResizeRows = false;
            this.dgvMostrar.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvMostrar.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnF2;
            this.dgvMostrar.Location = new System.Drawing.Point(0, 0);
            this.dgvMostrar.Name = "dgvMostrar";
            this.dgvMostrar.ReadOnly = true;
            this.dgvMostrar.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Bodoni MT", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dgvMostrar.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
            this.dgvMostrar.Size = new System.Drawing.Size(240, 150);
            this.dgvMostrar.TabIndex = 0;
            this.dgvMostrar.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvMostrar_CellClick);
            this.dgvMostrar.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvMostrar_CellContentClick);
            // 
            // tlpBuscarEnvCod
            // 
            this.tlpBuscarEnvCod.BackColor = System.Drawing.Color.LightCyan;
            this.tlpBuscarEnvCod.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
            this.tlpBuscarEnvCod.ColumnCount = 2;
            this.tlpBuscarEnvCod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpBuscarEnvCod.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpBuscarEnvCod.Location = new System.Drawing.Point(0, 0);
            this.tlpBuscarEnvCod.Name = "tlpBuscarEnvCod";
            this.tlpBuscarEnvCod.RowCount = 1;
            this.tlpBuscarEnvCod.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpBuscarEnvCod.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
            this.tlpBuscarEnvCod.Size = new System.Drawing.Size(400, 40);
            this.tlpBuscarEnvCod.TabIndex = 0;
            // 
            // tbBuscarEnvCod
            // 
            this.tbBuscarEnvCod.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
            this.tbBuscarEnvCod.Font = new System.Drawing.Font("Bodoni MT", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tbBuscarEnvCod.Location = new System.Drawing.Point(0, 0);
            this.tbBuscarEnvCod.MaxLength = 20;
            this.tbBuscarEnvCod.Name = "tbBuscarEnvCod";
            this.tbBuscarEnvCod.Size = new System.Drawing.Size(200, 30);
            this.tbBuscarEnvCod.TabIndex = 0;
            // 
            // tlpBotones
            // 
            this.tlpBotones.BackColor = System.Drawing.Color.LightCyan;
            this.tlpBotones.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.Single;
            this.tlpBotones.ColumnCount = 1;
            this.tlpBotones.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpBotones.Location = new System.Drawing.Point(0, 0);
            this.tlpBotones.Name = "tlpBotones";
            this.tlpBotones.RowCount = 1;
            this.tlpBotones.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpBotones.Size = new System.Drawing.Size(100, 46);
            this.tlpBotones.TabIndex = 0;
            // 
            // btVolver
            // 
            this.btVolver.BackColor = System.Drawing.Color.AliceBlue;
            this.btVolver.Font = new System.Drawing.Font("Bodoni MT", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btVolver.Location = new System.Drawing.Point(0, 0);
            this.btVolver.Margin = new System.Windows.Forms.Padding(12, 3, 3, 3);
            this.btVolver.Name = "btVolver";
            this.btVolver.Size = new System.Drawing.Size(75, 40);
            this.btVolver.TabIndex = 0;
            this.btVolver.Text = "Volver";
            this.btVolver.UseVisualStyleBackColor = false;
            this.btVolver.Click += new System.EventHandler(this.btVolver_Click);
            // 
            // btBuscarEnvCod
            // 
            this.btBuscarEnvCod.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btBuscarEnvCod.BackColor = System.Drawing.Color.AliceBlue;
            this.btBuscarEnvCod.Dock = System.Windows.Forms.DockStyle.Fill;
            this.btBuscarEnvCod.Font = new System.Drawing.Font("Bodoni MT", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btBuscarEnvCod.Location = new System.Drawing.Point(0, 0);
            this.btBuscarEnvCod.Name = "btBuscarEnvCod";
            this.btBuscarEnvCod.Size = new System.Drawing.Size(75, 23);
            this.btBuscarEnvCod.TabIndex = 0;
            this.btBuscarEnvCod.Text = "Buscar Código Envasado";
            this.btBuscarEnvCod.UseVisualStyleBackColor = false;
            this.btBuscarEnvCod.Click += new System.EventHandler(this.btBuscarEnvCod_Click);
            // 
            // dgvMostrar2
            // 
            this.dgvMostrar2.AllowUserToResizeRows = false;
            this.dgvMostrar2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvMostrar2.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnF2;
            this.dgvMostrar2.Location = new System.Drawing.Point(0, 0);
            this.dgvMostrar2.Name = "dgvMostrar2";
            this.dgvMostrar2.ReadOnly = true;
            this.dgvMostrar2.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Bodoni MT", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dgvMostrar2.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
            this.dgvMostrar2.Size = new System.Drawing.Size(240, 150);
            this.dgvMostrar2.TabIndex = 0;
            this.dgvMostrar2.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvMostrarMatPrima_CellClick);
            this.dgvMostrar2.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvMostrarMatPrima_CellContentClick);
            // 
            // btExportExcel2
            // 
            this.btExportExcel2.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btExportExcel2.BackColor = System.Drawing.Color.AliceBlue;
            this.btExportExcel2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.btExportExcel2.Font = new System.Drawing.Font("Bodoni MT", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btExportExcel2.Location = new System.Drawing.Point(0, 0);
            this.btExportExcel2.Name = "btExportExcel2";
            this.btExportExcel2.Size = new System.Drawing.Size(75, 23);
            this.btExportExcel2.TabIndex = 0;
            this.btExportExcel2.Text = "Exportar";
            this.btExportExcel2.UseVisualStyleBackColor = false;
            this.btExportExcel2.Click += new System.EventHandler(this.btExportExcel2_Click);
            // 
            // btExportExcel
            // 
            this.btExportExcel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btExportExcel.BackColor = System.Drawing.Color.AliceBlue;
            this.btExportExcel.Dock = System.Windows.Forms.DockStyle.Fill;
            this.btExportExcel.Font = new System.Drawing.Font("Bodoni MT", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btExportExcel.Location = new System.Drawing.Point(0, 0);
            this.btExportExcel.Name = "btExportExcel";
            this.btExportExcel.Size = new System.Drawing.Size(75, 23);
            this.btExportExcel.TabIndex = 0;
            this.btExportExcel.Text = "Exportar";
            this.btExportExcel.UseVisualStyleBackColor = false;
            this.btExportExcel.Click += new System.EventHandler(this.btExportExcel_Click);
            // 
            // tlpExportExcel2
            // 
            this.tlpExportExcel2.BackColor = System.Drawing.Color.Transparent;
            this.tlpExportExcel2.ColumnCount = 1;
            this.tlpExportExcel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpExportExcel2.Location = new System.Drawing.Point(0, 0);
            this.tlpExportExcel2.Name = "tlpExportExcel2";
            this.tlpExportExcel2.RowCount = 1;
            this.tlpExportExcel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpExportExcel2.Size = new System.Drawing.Size(100, 35);
            this.tlpExportExcel2.TabIndex = 0;
            // 
            // tlpExportExcel
            // 
            this.tlpExportExcel.BackColor = System.Drawing.Color.Transparent;
            this.tlpExportExcel.ColumnCount = 1;
            this.tlpExportExcel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpExportExcel.Location = new System.Drawing.Point(0, 0);
            this.tlpExportExcel.Name = "tlpExportExcel";
            this.tlpExportExcel.RowCount = 1;
            this.tlpExportExcel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpExportExcel.Size = new System.Drawing.Size(100, 35);
            this.tlpExportExcel.TabIndex = 0;
            // 
            // dgvMostrar3
            // 
            this.dgvMostrar3.AllowUserToResizeRows = false;
            this.dgvMostrar3.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dgvMostrar3.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnF2;
            this.dgvMostrar3.Location = new System.Drawing.Point(0, 0);
            this.dgvMostrar3.Name = "dgvMostrar3";
            this.dgvMostrar3.ReadOnly = true;
            this.dgvMostrar3.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Bodoni MT", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dgvMostrar3.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
            this.dgvMostrar3.Size = new System.Drawing.Size(240, 150);
            this.dgvMostrar3.TabIndex = 0;
            this.dgvMostrar3.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvMostrar3_CellClick);
            // 
            // btExportExcel3
            // 
            this.btExportExcel3.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
            this.btExportExcel3.BackColor = System.Drawing.Color.AliceBlue;
            this.btExportExcel3.Dock = System.Windows.Forms.DockStyle.Fill;
            this.btExportExcel3.Font = new System.Drawing.Font("Bodoni MT", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.btExportExcel3.Location = new System.Drawing.Point(0, 0);
            this.btExportExcel3.Name = "btExportExcel3";
            this.btExportExcel3.Size = new System.Drawing.Size(75, 23);
            this.btExportExcel3.TabIndex = 0;
            this.btExportExcel3.Text = "Exportar";
            this.btExportExcel3.UseVisualStyleBackColor = false;
            this.btExportExcel3.Click += new System.EventHandler(this.btExportExcel3_Click);
            // 
            // tlpExportExcel3
            // 
            this.tlpExportExcel3.BackColor = System.Drawing.Color.Transparent;
            this.tlpExportExcel3.ColumnCount = 1;
            this.tlpExportExcel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpExportExcel3.Location = new System.Drawing.Point(0, 0);
            this.tlpExportExcel3.Name = "tlpExportExcel3";
            this.tlpExportExcel3.RowCount = 1;
            this.tlpExportExcel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
            this.tlpExportExcel3.Size = new System.Drawing.Size(100, 35);
            this.tlpExportExcel3.TabIndex = 0;
            ((System.ComponentModel.ISupportInitialize)(this.dgvMostrar)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgvMostrar2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dgvMostrar3)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion 

        private void cargarMatPrimaEnDataGridView(string idProduccion)
        {
            try
            {
                if (dgvMostrar.CurrentCell == null)
                {
                    return;
                }

                dgvMostrar2.DataSource = null;
                dgvMostrar2.Rows.Clear();

                //string query = "SELECT pxmpxl.lote AS idLote, mp.nombre AS [Materia Prima], pxmpxl.cantidad AS [Cantidad Utilizada], pxmpxl.unidad AS Unidad, pxmpxl.produccion AS idProduccion FROM Produccion_X_MateriaPrima AS pxmpxl INNER JOIN MateriaPrima AS mp ON mp.ID=pxmpxl.materiaPrima  WHERE pxmpxl.lote='"+idLote+"'";

                string query = "SELECT pxmpxl.materiaPrima AS [ID Materia Prima], mp.nombre AS [Materia Prima],pxmpxl.lote AS [ID Lote], mp.codigo AS [Código],mp.descripcion AS [Descripción],mp.caracteristicas AS [Características] , pxmpxl.cantidad AS [Cantidad Utilizada], pxmpxl.unidad AS Unidad  FROM Produccion_X_MateriaPrima AS pxmpxl INNER JOIN MateriaPrima AS mp ON mp.ID=pxmpxl.materiaPrima  WHERE pxmpxl.produccion='" + idProduccion+ "'";

                adapter = SQLclass.obtenerAdapter(query);
                if (adapter != null)
                {
                    ds = new DataSet();
                    adapter.Fill(ds);

                    if (ds.Tables[0].Rows.Count <= 0)
                    {
                        MessageBox.Show("NO HAY NINGUNA MATERIA PRIMA CARGADA PARA LA PRODUCCIÓN SELECCIONADA \nÓ NO SE REALIZÓ NINGUNA PRODUCCIÓN CON ESE ID", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    else
                    {
                        dgvMostrar2.DataSource = ds.Tables[0];
                        
                    }
                }

                else
                {

                    MessageBox.Show("NO HAY NINGUNA MATERIA PRIMA CARGADA PARA LA PRODUCCIÓN SELECCIONADA \nÓ NO SE REALIZÓ NINGUNA PRODUCCIÓN CON ESE ID", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    //this.handler.backToPrincipal();
                }

            }
            catch (MiException ex)
            {

                CLogger.Append("[cargarMatPrimaEnDataGridView] Exception: " + ex, CLogger.ERROR);      //DEBUG

            }
        }

        private void cargarRemitoSalidaDataGridView(string idProduccion)
        {
            try
            {
                if (dgvMostrar.CurrentCell == null)
                {
                    return;
                }

                dgvMostrar3.DataSource = null;
                dgvMostrar3.Rows.Clear();

                //string query = "SELECT pxmpxl.lote AS idLote, mp.nombre AS [Materia Prima], pxmpxl.cantidad AS [Cantidad Utilizada], pxmpxl.unidad AS Unidad, pxmpxl.produccion AS idProduccion FROM Produccion_X_MateriaPrima AS pxmpxl INNER JOIN MateriaPrima AS mp ON mp.ID=pxmpxl.materiaPrima  WHERE pxmpxl.lote='"+idLote+"'";

                string query = "SELECT rsxpr.remitoSalida AS [ID Remitos de Salida], rs.codigo AS [Código], rs.fechaRemitoSalida AS [Fecha de Remito de Salida], rsxpr.cantidadProductos [Cantidad de Productos] FROM RemitoSalida_X_Produccion AS rsxpr INNER JOIN RemitoSalida as rs ON rs.ID= rsxpr.remitoSalida WHERE rsxpr.produccion='" + idProduccion + "'";

                adapter = SQLclass.obtenerAdapter(query);
                if (adapter != null)
                {
                    ds = new DataSet();
                    adapter.Fill(ds);

                    if (ds.Tables[0].Rows.Count <= 0)
                    {
                        MessageBox.Show("NO HAY NINGÚN REMITOP DE SALIDA LA PRODUCCIÓN SELECCIONADA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    else
                    {
                        dgvMostrar3.DataSource = ds.Tables[0];

                    }
                }

                else
                {

                    MessageBox.Show("NO HAY NINGÚN REMITOP DE SALIDA LA PRODUCCIÓN SELECCIONADA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    //this.handler.backToPrincipal();
                }

            }
            catch (MiException ex)
            {

                CLogger.Append("[cargarRemitoSalidaDataGridView] Exception: " + ex, CLogger.ERROR);      //DEBUG

            }
        }

        #region BOTONES
        private void btVolver_Click(object sender, EventArgs e)
        {
            this.handler.backToPrincipal();
        }

        private void btBuscarEnvCod_Click(object sender, EventArgs e)
        {
            if (dgvMostrar.CurrentCell == null)
                return;

            if (dgvMostrar.Rows.Count <= 0)
                return;

            dgvMostrar.ClearSelection();

            if (!string.IsNullOrWhiteSpace(tbBuscarEnvCod.Text))
            {
                string searchValue = tbBuscarEnvCod.Text;
                try
                {
                    foreach (DataGridViewRow row in dgvMostrar.Rows)
                    {
                        if (row.Cells[3].Value.ToString().Equals(searchValue))
                        {
                            dgvMostrar.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                            row.Selected = true;

                            //MessageBox.Show("ENCONTRE: "+inRowFinded, "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            tbBuscarEnvCod.Clear();

                            dgvMostrar.CurrentCell = row.Cells[0];
                            //dgvMostrarLotes.FirstDisplayedScrollingRowIndex=row.Index;

                            if (dgvMostrar.CurrentCell != null)
                            {
                                cargarMatPrimaEnDataGridView(dgvMostrar[0, dgvMostrar.CurrentCell.RowIndex].Value.ToString());
                                
                            }
                            break;

                        }

                    }

                }
                catch (Exception exc)
                {
                    tbBuscarEnvCod.Clear();
                    MessageBox.Show("NO SE ENCONTRO EL CÓDIGO DE ENVASADO BUSCADO", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    // CLogger.Append("[btBuscarProducto_Click] Exception: " + exc, CLogger.ERROR);      //DEBUG
                }
            }
            else
            {
                MessageBox.Show("NO SE INGRESO CÓDIGO DE ENVASADO A BUSCAR", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }
        }

      
        private void dgvMostrar_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            dgvMostrar.SelectionMode = DataGridViewSelectionMode.CellSelect;
            dgvMostrar.CurrentCell = dgvMostrar.Rows[dgvMostrar.CurrentCell.RowIndex].Cells[0];

            if (dgvMostrar.CurrentCell != null)
            {
                cargarMatPrimaEnDataGridView(dgvMostrar[0,dgvMostrar.CurrentCell.RowIndex].Value.ToString());
                cargarRemitoSalidaDataGridView(dgvMostrar[0, dgvMostrar.CurrentCell.RowIndex].Value.ToString());
            }
        }

        private void dgvMostrar_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            dgvMostrar.SelectionMode = DataGridViewSelectionMode.CellSelect;
            dgvMostrar.CurrentCell = dgvMostrar.Rows[dgvMostrar.CurrentCell.RowIndex].Cells[0];

            if (dgvMostrar.CurrentCell != null)
            {
                cargarMatPrimaEnDataGridView(dgvMostrar[0, dgvMostrar.CurrentCell.RowIndex].Value.ToString());
                cargarRemitoSalidaDataGridView(dgvMostrar[0, dgvMostrar.CurrentCell.RowIndex].Value.ToString());
            }
        }

        private void dgvMostrarMatPrima_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            
            dgvMostrar2.SelectionMode = DataGridViewSelectionMode.CellSelect;
            dgvMostrar2.CurrentCell = dgvMostrar2.Rows[dgvMostrar2.CurrentCell.RowIndex].Cells[0];
        }

        private void dgvMostrarMatPrima_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            dgvMostrar2.SelectionMode = DataGridViewSelectionMode.CellSelect;
            dgvMostrar2.CurrentCell = dgvMostrar2.Rows[dgvMostrar2.CurrentCell.RowIndex].Cells[0];
        }

        private void dgvMostrar3_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            dgvMostrar3.SelectionMode = DataGridViewSelectionMode.CellSelect;
            dgvMostrar3.CurrentCell = dgvMostrar3.Rows[dgvMostrar3.CurrentCell.RowIndex].Cells[0];
        }

        #endregion

        #region EXCEL

        private void btExportExcel_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvMostrar.CurrentCell == null)
                {
                    MessageBox.Show("NO HAY DATOS EN LA TABLA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    //MessageBox.Show("NO HAY CELDA SELECCIONADA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                dgvMostrar.SelectionMode = DataGridViewSelectionMode.CellSelect;
                dgvMostrar.CurrentCell = dgvMostrar.Rows[dgvMostrar.CurrentCell.RowIndex].Cells[0];


                copyAlltoClipboard();
                Microsoft.Office.Interop.Excel.Application xlexcel;
                Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

                object misValue = System.Reflection.Missing.Value;
                xlexcel = new Microsoft.Office.Interop.Excel.Application();

                xlexcel.Visible = true;

                xlWorkBook = xlexcel.Workbooks.Add(misValue);

                xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                xlWorkSheet.Name = "Trazabilidad Cod Envasado";

                Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[2, 1];
                CR.Select();
                xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);

                formatearExcel1(xlWorkSheet);


            }
            catch (Exception ex)
            {
                CLogger.Append("[btExportExcel_Click] Exception  export: " + ex, CLogger.INFO);      //DEBUG
            }
        
        }

        private static void formatearExcel1(Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet)
        {                         
            xlWorkSheet.Cells[1, 1] = "ID Producción";
            xlWorkSheet.Cells[1, 2] = "Producto";
            xlWorkSheet.Cells[1, 3] = "ID Envasado";
            xlWorkSheet.Cells[1, 4] = "Código Envasado";
            xlWorkSheet.Cells[1, 5] = "Fecha Fin de Envasado";
            xlWorkSheet.Cells[1, 6] = "Cantidad de Paquetes";
            xlWorkSheet.Cells[1, 7] = "Observación1";
            xlWorkSheet.Cells[1, 8] = "Observación2";
            xlWorkSheet.Cells[1, 9] = "Observación3";
            xlWorkSheet.Cells[1, 10] = "Observación4";

            xlWorkSheet.Cells[1, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 1].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 2].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 2].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 3].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 3].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 4].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 4].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 5].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 5].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 6].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 6].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 7].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 7].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 8].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 8].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 9].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 9].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 10].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 10].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Columns.AutoFit();
        }

        private void copyAlltoClipboard()
        {
            dgvMostrar.SelectAll();
            DataObject dataObj = dgvMostrar.GetClipboardContent();
            if (dataObj != null)
                Clipboard.SetDataObject(dataObj);
        }


        private void btExportExcel2_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvMostrar2.CurrentCell == null)
                {
                    MessageBox.Show("NO HAY DATOS EN LA TABLA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                dgvMostrar2.SelectionMode = DataGridViewSelectionMode.CellSelect;
                dgvMostrar2.CurrentCell = dgvMostrar2.Rows[dgvMostrar2.CurrentCell.RowIndex].Cells[0];

                copyAlltoClipboard2();
                Microsoft.Office.Interop.Excel.Application xlexcel;
                Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

                object misValue = System.Reflection.Missing.Value;
                xlexcel = new Microsoft.Office.Interop.Excel.Application();

                xlexcel.Visible = true;

                xlWorkBook = xlexcel.Workbooks.Add(misValue);

                xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                xlWorkSheet.Name = "Materia Prima por Cod Envasado";

                Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[2, 2];
                CR.Select();
                xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);

                formatearExcel2(xlWorkSheet);

            }
            catch (Exception ex)
            {
                CLogger.Append("[btExportExcel2_Click] Exception  export: " + ex, CLogger.INFO);      //DEBUG
            }
        }

        private void formatearExcel2(Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet)
        {
            
            xlWorkSheet.Cells[1, 2] = "ID Materia Prima";
            xlWorkSheet.Cells[1, 3] = "Nombre Materia Prima";
            xlWorkSheet.Cells[1, 4] = "ID Lote";
            xlWorkSheet.Cells[1, 5] = "Código Materia Prima";
            xlWorkSheet.Cells[1, 6] = "Descripción";
            xlWorkSheet.Cells[1, 7] = "Características";
            xlWorkSheet.Cells[1, 8] = "Cantidad Utilizada";
            xlWorkSheet.Cells[1, 9] = "Unidad";
            

            xlWorkSheet.Cells[1, 1] = "ID Producción";

            xlWorkSheet.Cells[2, 1] = dgvMostrar[0, dgvMostrar.CurrentCell.RowIndex].Value.ToString();

            xlWorkSheet.Cells[1, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 1].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 2].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 2].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 3].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 3].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 4].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 4].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 5].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 5].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 6].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 6].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
            
            xlWorkSheet.Cells[1, 7].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 7].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 8].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 8].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
            
            xlWorkSheet.Cells[1, 9].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 9].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);
            
            xlWorkSheet.Columns.AutoFit();
        }

        private void copyAlltoClipboard2()
        {
            dgvMostrar2.SelectAll();
            DataObject dataObj = dgvMostrar2.GetClipboardContent();
            if (dataObj != null)
                Clipboard.SetDataObject(dataObj);
        }



        private void btExportExcel3_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvMostrar3.CurrentCell == null)
                {
                    MessageBox.Show("NO HAY DATOS EN LA TABLA", "INFO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }

                dgvMostrar3.SelectionMode = DataGridViewSelectionMode.CellSelect;
                dgvMostrar3.CurrentCell = dgvMostrar3.Rows[dgvMostrar3.CurrentCell.RowIndex].Cells[0];

                copyAlltoClipboard3();
                Microsoft.Office.Interop.Excel.Application xlexcel;
                Microsoft.Office.Interop.Excel.Workbook xlWorkBook;
                Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet;

                object misValue = System.Reflection.Missing.Value;
                xlexcel = new Microsoft.Office.Interop.Excel.Application();

                xlexcel.Visible = true;

                xlWorkBook = xlexcel.Workbooks.Add(misValue);

                xlWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                xlWorkSheet.Name = "Remito Salida por Cod Envasado";

                Microsoft.Office.Interop.Excel.Range CR = (Microsoft.Office.Interop.Excel.Range)xlWorkSheet.Cells[2, 2];
                CR.Select();
                xlWorkSheet.PasteSpecial(CR, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true);

                formatearExcel3(xlWorkSheet);

            }
            catch (Exception ex)
            {
                CLogger.Append("[btExportExcel3_Click] Exception  export: " + ex, CLogger.INFO);      //DEBUG
            }
        }

        private void formatearExcel3(Microsoft.Office.Interop.Excel.Worksheet xlWorkSheet)
        {
                        
            xlWorkSheet.Cells[1, 2] = "ID Remito de Salida";
            xlWorkSheet.Cells[1, 3] = "Código";
            xlWorkSheet.Cells[1, 4] = "Fecha de Remito de Salida";
            xlWorkSheet.Cells[1, 5] = "Cantidad de Productos";


            xlWorkSheet.Cells[1, 1] = "ID Producción";

            xlWorkSheet.Cells[2, 1] = dgvMostrar[0, dgvMostrar.CurrentCell.RowIndex].Value.ToString();

            xlWorkSheet.Cells[1, 1].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 1].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 2].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 2].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 3].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 3].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 4].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 4].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);

            xlWorkSheet.Cells[1, 5].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
            xlWorkSheet.Cells[1, 5].Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.White);


            xlWorkSheet.Columns.AutoFit();
        }

        private void copyAlltoClipboard3()
        {
            dgvMostrar3.SelectAll();
            DataObject dataObj = dgvMostrar3.GetClipboardContent();
            if (dataObj != null)
                Clipboard.SetDataObject(dataObj);
        }

        #endregion

       

       

    }


}
